home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / AimIM.js < prev    next >
Encoding:
JavaScript  |  2002-06-03  |  8.2 KB  |  261 lines

  1. /*
  2.  * Function:  aimIMObject()
  3.  * Arguments: None
  4.  * Return: nsIAimIM interface
  5.  * Description:  This function is queries for it and returns the nsIAimIM interface 
  6. */
  7.  
  8. function aimIMObject()
  9. {
  10.     var pIIMManager = aimManager();
  11.     if ( pIIMManager )
  12.         return pIIMManager.QueryInterface(Components.interfaces.nsIAimIM);
  13.     else
  14.         return null;
  15. }
  16.  
  17. /*
  18.  * Function:  aimIMInvokeIMForm(screenName)
  19.  * Arguments: 
  20.  *    screenName  --  the buddy name which appears on the To field in the IM window (selected  buddy name)
  21.  * Return: None
  22.  * Description:  This function calls the InvokeIMUI function which on the AimIM interface which puts 
  23.  * up the IM conversation window. The Screenname param which is passed, is used to prefill the To field.
  24. */
  25.  
  26. function aimIMInvokeIMForm(screenName)
  27. {
  28.     var pIAimIM = aimIMObject();
  29.     if(pIAimIM)
  30.         pIAimIM.InvokeIMUI(screenName, null);
  31. }
  32.  
  33. /*
  34.  * Function:  aimIMDoesIMExist(screenName)
  35.  * Arguments: 
  36.  *    screenName  --  screen name to be checked
  37.  * Return: Boolean
  38.  * Description:  This function is used to find out if there is already an existing aim conversation 
  39.  * going on with the specified screenname. If there is already a window open with the screenname in 
  40.  * the To:field or title of the window, then this returns true. If no window exists for this screen 
  41.  * name, this returns false;
  42. */
  43.  
  44. function aimIMDoesIMExist(screenName)
  45. {
  46.     var pIAimIM = aimIMObject();
  47.     if(pIAimIM)
  48.         {
  49.         var pWindow = pIAimIM.GetExistingIM(screenName);
  50.         if(pWindow)
  51.             return true;
  52.         }
  53.     return false;
  54. }
  55.  
  56. /**************** Private Methods ***********************/
  57.  
  58. /*
  59.  * Function:  aimPIMObject()
  60.  * Arguments: None
  61.  * Return: nsPIAimIM interface
  62.  * Description:  This function queries for it and returns the nsPIAimIM interface 
  63. */
  64.  
  65. function aimPIMObject()
  66. {
  67.     var pIIMManager = aimManager();
  68.     if(pIIMManager)
  69.         return pIIMManager.QueryInterface(Components.interfaces.nsPIAimIM);
  70.     else
  71.         return null;
  72. }
  73.  
  74. /*
  75.  * Function:  aimPIMSendIM(wnd, screenName, message)
  76.  * Arguments: 
  77.  *    wnd --    window from which the message is sent
  78.  *    screenName  --  screenname to whom the message is to be sent
  79.  *    message --  message to be sent. 
  80.  * Return:  None 
  81.  * Description:  This function is used to send a instant message from the window 
  82.  * where the Send button is clicked. The message (the formatted contents of the IM window)
  83.  * is sent to the screenname  which is the second input parameter ( from the To:field in IM window). 
  84. */
  85.  
  86. function aimPIMSendIM(wnd, screenName, message, text)
  87. {
  88.     var pPIAimIM = aimPIMObject();
  89.     if(pPIAimIM)
  90.         pPIAimIM.SendMsg(wnd, screenName, message, text);
  91. }
  92.  
  93.  
  94. /*
  95.  * Function:  setStyles ()
  96.  * Arguments: 
  97.  * Return:  None 
  98.  * Description:  This function is used to set the style elements,
  99.  *               which are read from the prefs, and overridden by
  100.  *               getStyles.
  101.  *               
  102.  * Author: jelwell@netscape.com
  103. */
  104.  
  105.  
  106. var sessionType =aimPrefsManager().GetIntPref("aim.session.sessiontype", null, false);
  107. if(sessionType == 0) {
  108.   var aimStylePrefManager = aimPrefsManager();
  109.   var faceType = aimStylePrefManager.GetCharPref("aim.style.fontface", null, false);
  110.   var fontSize = aimStylePrefManager.GetCharPref("aim.style.fontsize", null, false);
  111.   var textstyles = aimStylePrefManager.GetCharPref("aim.style.textstyles", null, false);
  112.   var italics = aimStylePrefManager.GetBoolPref("aim.style.italics", null, false);
  113.   var bold = aimStylePrefManager.GetBoolPref("aim.style.bold", null, false);
  114.   var underline = aimStylePrefManager.GetBoolPref("aim.style.underline", null, false);
  115.   var currentColor = aimStylePrefManager.GetCharPref("aim.style.forecolor", null, false);
  116.   var backgroundColor = aimStylePrefManager.GetCharPref("aim.style.backcolor", null, false);
  117. }
  118. if (sessionType ==2) {
  119.   var aimStylePrefManager = aimPrefsManager();
  120.   var faceType = aimStylePrefManager.GetCharPref("icq.style.fontface", null, false);
  121.   var fontSize = aimStylePrefManager.GetCharPref("icq.style.fontsize", null, false);
  122.   var textstyles = aimStylePrefManager.GetCharPref("icq.style.textstyles", null, false);
  123.   var italics = aimStylePrefManager.GetBoolPref("icq.style.italics", null, false);
  124.   var bold = aimStylePrefManager.GetBoolPref("icq.style.bold", null, false);
  125.   var underline = aimStylePrefManager.GetBoolPref("icq.style.underline", null, false);
  126.   var currentColor = aimStylePrefManager.GetCharPref("icq.style.forecolor", null, false);
  127.   var backgroundColor = aimStylePrefManager.GetCharPref("icq.style.backcolor", null, false);
  128. }
  129.  
  130. function setStyles ()
  131. {
  132.   // find body node
  133.   var bodyelement = GetBodyElement();
  134.   if (bodyelement)
  135.   {
  136.     if (backgroundColor && backgroundColor != "")
  137.       bodyelement.setAttribute("bgcolor", backgroundColor);
  138.     var backgroundcolor = document.getElementById("cmd_backgroundColor");
  139.     if (backgroundcolor)
  140.       backgroundcolor.setAttribute("state", backgroundColor);
  141.   }
  142.   if (currentColor && currentColor != "") {
  143.     top.editorShell.SetTextProperty("font", "color", currentColor);
  144. //  bodyelement.setAttribute("text", text_color);
  145.     var commandcolor = document.getElementById("cmd_fontColor");
  146.     if (commandcolor)
  147.       commandcolor.setAttribute("state", currentColor);
  148.   }
  149.   if (textstyles && textstyles != "") {
  150.     if (italics)
  151.       top.editorShell.SetTextProperty("i", "", "");
  152.     if (bold)
  153.       top.editorShell.SetTextProperty("b", "", "");
  154.     if (underline)
  155.       top.editorShell.SetTextProperty("u", "", "");
  156.   }
  157.   if (fontSize && fontSize != "")
  158.     top.editorShell.SetTextProperty(fontSize, "", "");
  159.   if (faceType == "tt")
  160.   {
  161.     top.editorShell.SetTextProperty("tt", "", "");
  162.   }
  163.   else
  164.   if (faceType && faceType != "")
  165.   {
  166.     top.editorShell.SetTextProperty("font", "face", faceType);
  167.   }
  168.   document.getElementById("cmd_preferences").setAttribute("disabled", "false");
  169. }
  170.  
  171. /*
  172.  * Function:  getStyles ()
  173.  * Arguments: 
  174.  * Return:  None 
  175.  * Description:  This function is used to get the style elements,
  176.  *               to be saved for retrieval for the next message
  177.  *               sent in this session.
  178.  *
  179.  * Author: jelwell@netscape.com
  180. */
  181.  
  182. function getStyles ()
  183. {
  184.   top.editorShell.SelectAll();
  185.  
  186.   var firstHas = new Object;
  187.   var anyHas = new Object;
  188.   var allHas = new Object;
  189.   allHas.value = false;
  190.  
  191.   //    Find Font Face
  192.   //    Fixed width (second menu item) is special case: old TT ("teletype") attribute
  193.   top.editorShell.GetTextProperty("tt", "", "", firstHas, anyHas, allHas);
  194.   if (!allHas.value)
  195.   {
  196.     var children = top.document.getElementById("FontFacePopup").childNodes;
  197.     // Skip over default, TT, and separator
  198.     for (var i = 3; i < children.length; i++)
  199.     {
  200.       var menuitem = children[i];
  201.       faceType = menuitem.getAttribute("value");
  202.       if (faceType)
  203.       {
  204.         top.editorShell.GetTextProperty("font", "face", faceType, firstHas, anyHas, allHas);
  205.         if (allHas.value)
  206.         {
  207.           break;
  208.         }
  209.       }
  210.     }
  211.     if (!allHas.value)
  212.     faceType = "";
  213.   }
  214.   else
  215.     faceType = "tt";
  216.   //    End Find Font Face
  217.  
  218.   //    Find Big or Small
  219.   top.editorShell.GetTextProperty("big", "", "", firstHas, anyHas, allHas);
  220.   if (allHas.value)
  221.   {
  222.     fontSize = "big";
  223.   }
  224.   else
  225.   {
  226.     top.editorShell.GetTextProperty("small", "", "", firstHas, anyHas, allHas);
  227.   if (allHas.value)
  228.     fontSize = "small";
  229.   else
  230.     fontSize = "";
  231.  
  232.   }
  233.  //    End Find Big or Small
  234.   top.editorShell.GetTextProperty("i", "", "", firstHas, anyHas, allHas);
  235.   if (allHas.value)
  236.     italics = true;
  237.   else
  238.     italics = false;
  239.   top.editorShell.GetTextProperty("b", "", "", firstHas, anyHas, allHas);
  240.   if (allHas.value)
  241.     bold = true;
  242.   else
  243.     bold = false;
  244.   top.editorShell.GetTextProperty("u", "", "", firstHas, anyHas, allHas);
  245.   if (allHas.value)
  246.     underline = true;
  247.   else
  248.     underline = false;
  249.  
  250.   if (italics || bold || underline)
  251.     textstyles = 1;
  252.   var commandcolor = document.getElementById("cmd_fontColor");
  253.   if (commandcolor) {
  254.     currentColor = commandcolor.getAttribute("state");
  255.   }
  256.   var backgroundcolor = document.getElementById("cmd_backgroundColor");
  257.   if (backgroundcolor) {
  258.     backgroundColor = backgroundcolor.getAttribute("state");
  259.   }
  260. }
  261.